/**
 * Copyright (c) 2015—2017 Zerone.Co.Ltd. All rights reserved.
 */
package com.zerone.pay.merchant.executor;

import com.acooly.core.utils.mapper.BeanCopier;
import com.zerone.payment.common.exception.PaymentException;
import org.springframework.beans.factory.annotation.Autowired;

import com.acooly.core.common.facade.SingleResult;
import com.acooly.module.adk.executor.InvokeServiceAdapter;
import com.acooly.module.adk.executor.ServiceContext;
import com.acooly.module.adk.executor.annotation.Invoke;
import com.zerone.facade.merchant.info.MerchantPayInfo;
import com.zerone.facade.merchant.order.MerchantPayQueryOrder;
import com.zerone.pay.merchant.repository.dao.MerchantPayDao;
import com.zerone.pay.merchant.repository.entity.MerchantPayEntity;

/**
 *
 * @author glassescat <a href="">零一零一科技</a>
 */
@Invoke(serviceName = "queryMerchantPay",logName = "merchant")
public class MerchantPayQueryInvoke extends InvokeServiceAdapter<MerchantPayQueryOrder,SingleResult<MerchantPayInfo>> {

    @Autowired
    private MerchantPayDao merchantPayDao;

    @Override
    public void invoke(ServiceContext<MerchantPayQueryOrder, SingleResult<MerchantPayInfo>> serviceContext) {
        MerchantPayQueryOrder order = serviceContext.getParameter();
        MerchantPayEntity entity = merchantPayDao.findMerchantPay(order.getMerchantId(),order.getPayTrusts());
        if (entity == null ){
            throw new PaymentException("商户支付未配置");
        }
        MerchantPayInfo merchantPayInfo = new MerchantPayInfo();
        BeanCopier.copy(entity,merchantPayInfo);
        serviceContext.result().setDto(merchantPayInfo);
    }
}
